﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="JS._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <input type="hidden" name="abc" id="abc" value="/aaa" />
        <textarea id="show" cols="50" rows="20"></textarea>
    </div>
    <asp:TextBox ID="tbTestChange" runat="server" />s
    </form>
</body>
</html>
<script type="text/javascript">
    function xHTML(b) {
        //var b = document.body;

        var childs = b.childNodes;
        //var childrens = b.children;

        if (childs.length == 0) {
            document.getElementById("show").value += "<" + b.nodeName.toLowerCase();
            if (b.attributes.length > 0) {
                for (var ii = 0; ii < b.attributes.length; ii++) {
                    var specTags = /value|option|shape|coords/;
                    if (b.attributes[ii].specified || b.attributes[ii].name.match(specTags)) {
                        document.getElementById("show").value += " " + b.attributes[ii].name.toLowerCase() + "=";
                        document.getElementById("show").value += "\"" + escape(b.attributes[ii].value.toLowerCase()) + "\"";
                    }
                }
            }
            document.getElementById("show").value += ">";
            if (b.nodeName == "SCRIPT") {
                document.getElementById("show").value += b.innerHTML;
            } else {
                if (b.lastChild) {
                    document.getElementById("show").value += b.lastChild.nodeValue;
                }
            }
            document.getElementById("show").value += "</" + b.nodeName.toLowerCase() + ">";
            document.getElementById("show").value += "\n";
        } else {
            for (var i = 0; i < childs.length; i++) {
                if (childs[i].childNodes.length > 1 && childs[i].nodeType == 1) {
                    xHTML(childs[i]);
                } else {
                    if (childs[i].nodeType == 3) {
                        document.getElementById("show").value += childs[i].nodeValue + "\n";
                    } else {
                        document.getElementById("show").value += "<" + childs[i].nodeName.toLowerCase();
                        if (childs[i].attributes.length > 0) {
                            for (var ii = 0; ii < childs[i].attributes.length; ii++) {
                                if (childs[i].attributes[ii].specified) {
                                    document.getElementById("show").value += " " + childs[i].attributes[ii].name.toLowerCase() + "=";
                                    document.getElementById("show").value += "\"" + childs[i].attributes[ii].value.toLowerCase() + "\"";
                                }
                            }
                        }
                        document.getElementById("show").value += ">";
                        if (childs[i].nodeName == "SCRIPT") {
                            document.getElementById("show").value += childs[i].innerHTML;
                        } else {
                            if (childs[i].lastChild) {
                                document.getElementById("show").value += childs[i].lastChild.nodeValue;
                            }
                        }
                        document.getElementById("show").value += "</" + childs[i].nodeName.toLowerCase() + ">";
                        document.getElementById("show").value += "\n";
                    }
                }
            }
        }
    };
    xHTML(document.getElementById("abc"));
</script>